﻿unit MessageHint_u;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls, Vcl.ExtCtrls,IniFiles,
  IWVCLBaseControl, IWBaseControl, IWBaseHTMLControl, IWControl, IWCompEdit,
  IWCompTimeEdit;

type
  TwMessageHint = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Memo1: TMemo;
    Button1: TButton;
    TreeView1: TTreeView;
    Edit1: TEdit;
    DateTimePicker1: TDateTimePicker;
    Edit2: TEdit;
    Edit3: TEdit;
    DateTimePicker2: TDateTimePicker;
    procedure Button1Click(Sender: TObject);
    procedure Edit2Exit(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  wMessageHint: TwMessageHint;

implementation

{$R *.dfm}

procedure TwMessageHint.Button1Click(Sender: TObject);
 var
  inifile:TInifile;
  iniFileName,sAppPath:string;
  d01:Double ;
begin
  if  Trim(Edit1.Text )='' then
  begin
    MessageBox(Self.Handle,PChar('Display times is empty ,Don''t save the message!'),PChar(Application.Title),MB_ICONWARNING);
    Exit ;
  end;

  if Trim(Memo1.Lines.Text )=''  then
  begin
    MessageBox(Self.Handle,PChar('Message content is empty ,Don''t save the message!'),PChar(Application.Title),MB_ICONWARNING);
    Exit ;
  end;

  //dou01:=TDateTime (DateTimePicker1.Date);
  //dou02:=TDateTime(DateTimePicker2.Time);
  //dou03:=dou01+dou02;

  //ShowMessage(FormatDateTime ('yymmddhhmmss',dou03));
  DateTimePicker1.Time :=DateTimePicker2.Time ;
  d01:= DateTimePicker1.DateTime ;
  try


    sAppPath:=ExtractFilePath(Application.ExeName);
    iniFileName:=sAppPath+'testset.ini';
   // if fileExists(iniFileName) then DeleteFile(iniFileName);
     {
      [Sysconfig]
        SQLMonitor=true
     }
    inifile:=TInifile.Create(iniFileName);
    //if not FileExists(pChar(iniFileName)) then
    begin
      inifile.writeString('Message_'+Edit1.Text ,'Message_Text',Memo1.Lines.Text);
      inifile.writeString('Message_'+Edit1.Text ,'Message_Time',FloatToStr(d01));
      inifile.writeinteger('Message_'+Edit1.Text ,'Message_Int',StrToIntDef (Edit2.Text,1));
    end ;
    ShowMessage('Created message successful  !');
  finally;
    FreeAndNil(inifile);
    Self.Close ;
  end;
end;

procedure TwMessageHint.Edit2Exit(Sender: TObject);
begin
  if  StrToIntDef(Edit2.Text ,1)>3 then
  begin
    Edit2.SetFocus ;
    ShowMessage('請輸入不大於3的正整數');
    Exit;
  end;

end;

procedure TwMessageHint.FormShow(Sender: TObject);
begin
  DateTimePicker1.DateTime :=Now;
  DateTimePicker2.DateTime :=Now;
end;

end.


方法1：
procedure TForm1.btn1Click(Sender:TObject);
var    s:string;
begin
     //yyyy-mm-dd后面带了一个空格，为了拼上time时格式正确
     s:=FormatDateTime('yyyy-mm-dd ',dtp1.Date) + FormatDateTime('hh:mm:ss',dtp2.Time);  //這個不好，本機還是可以的
end;


方法2：

procedure TForm1.btn1Click(Sender:TObject);
var    s:string;
begin
     //date、time值合并到一个控件。
     dtp1.Time:=dtp2.Time;  //這個更好，利於在不同的時間格式 yyyy-mm-dd；yyyy/mm/dd;等
     s:=FormatDateTime('yyyy-mm-dd hh:mm:ss',dtp1.DateTime);
end;
